/* 
 * @(#)ActionUtils.java    Created on 2009-11-3
 * Copyright (c) 2009 ZDSoft Networks, Inc. All rights reserved.
 * $Id$
 */
package com.abc.demo.common.utils;

import java.util.Map;

import org.apache.struts2.json.JSONResult;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.config.entities.ResultConfig;

/**
 * 和框架中Action相关的工具类.
 * 
 * @author huangwj
 * @version $Revision: 1.0 $, $Date: 2009-11-3 下午07:18:23 $
 */
public abstract class ActionUtils {

    /**
     * 判断Action是否为采用JSON为输出方式(ResultType)的Action.
     * 
     * @param invocation
     *            ActionInvocation对象
     * @return true/false
     */
    public static boolean isJsonAction(ActionInvocation invocation) {
        boolean isJsonAction = false;
        Map<String, ResultConfig> results = invocation.getProxy().getConfig().getResults();
        if (!results.isEmpty()) {
            ResultConfig resultConf = results.values().iterator().next();
            if (JSONResult.class.getName().equals(resultConf.getClassName())) {
                isJsonAction = true;
            }
        }
        return isJsonAction;
    }

}
